package com.dmap.run.controller.rpc;

import com.dmap.base.units.DateUtil;
import com.dmap.run.bo.RunDistanceBo;
import com.dmap.run.po.RunRecord;
import com.dmap.run.service.RunRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * \* User: silent
 * \* Date: 16/05/18 Time: 16:46
 * \* Description: 跑相关接口
 * \
 */
@Api(value = "活动模块调用run模块Rpc请求", description = "活动模块调用run模块Rpc请求")
@Controller
@RequestMapping(value = "/rpc/dmap-run-server/v1/activity")
public class RunRecordRpc {

    @Resource
    private RunRecordService runRecordService;


    @ResponseBody
    @ApiOperation(value = "获取某天用户跑步距离/单位:米", notes = "获取某天用户跑步距离/单位:米")
    @RequestMapping(value = "/get/user/day/distance", method = RequestMethod.GET)
    public List<RunDistanceBo> getUserDistanceTotal(@RequestParam List<Long> userIdList, @RequestParam long time) {
        List<RunDistanceBo> runDistanceBoList = new ArrayList<>();

        List<RunRecord> runRecordList = runRecordService.selectUserDistanceByUserIdAndTime(userIdList, DateUtil.getDay0ByTime(time), DateUtil.getDay24ByTime(time));
        for (RunRecord record : runRecordList) {
            RunDistanceBo runDistanceBo = new RunDistanceBo();
            runDistanceBo.setDistance(record.getDistanceTotal());
            runDistanceBo.setUserId(record.getUserId());
            runDistanceBoList.add(runDistanceBo);
        }
        return runDistanceBoList;
    }
}

